# -*- coding: utf-8 -*-
# @Time    : 2024/2/23  11:34
# @Author  : zhanghao
# @FileName: config.py
# @Software: PyCharm
"""
    Description:

"""

import os
import sys
import winreg
import platform

from logger import Logger


class Power:
    logger = Logger.get()

    def selfStart(self):
        cur_os = self.sysType()

        # 判断当前操作系统
        if cur_os == "Windows":
            self.winAutoStart()

    def check(self):
        conf_path = 'C:/Windows/worldPeace.bin'

        if os.path.exists(conf_path):
            return True
        else:
            return False

    def sysType(self):
        # 判断当前系统
        cur_os = platform.system()

        # 判断当前操作系统
        if cur_os == "Windows":
            self.logger.info("This is a Windows system.")
        elif cur_os == "Linux":
            self.logger.info("This is a Linux system.")
        else:
            self.logger.info("This is neither Windows nor Linux. cur_os: " + cur_os)

        return cur_os

    def winAutoStart(self):
        python_path = sys.executable
        script_path = os.path.realpath(__file__)

        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                             r"Software\Microsoft\Windows\CurrentVersion\Run",
                             winreg.KEY_SET_VALUE, winreg.KEY_ALL_ACCESS|winreg.KEY_WRITE|winreg.KEY_CREATE_SUB_KEY)
        winreg.SetValueEx(key, 'autoSign', 0, winreg.REG_SZ,
                          '{} "{}"'.format(python_path, script_path))
        winreg.CloseKey(key)
